﻿@model Hospital

@{
    ViewBag.Title = "病例报告列表";
    Layout = "~/Views/Shared/Master.cshtml";
}
<script type="text/javascript" src="../../Scripts/jquery-1.7.2.js">
</script>
 @{Html.Telerik().Window().Name("CRFListSelfWindouw").Title("病例报告列表").HtmlAttributes(new { @class = "ContentLargeWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@*@using (Html.BeginForm())
{ 
   <p> <label for="HospitalCode">医院编号</label>
    @Html.TextBox("HospitalCode")
    <label for="GroupCode">分组序号</label>
    @Html.TextBox("GroupCode")
    </p>
    <label for="ResearcherName">研究者</label>
    @Html.TextBox("ResearcherName")
    <label for="StartTime" >开始时间</label>
    @Html.DateEditor("StartTime")
    <button class="t-button t-state-default" type="submit">查询</button>
}*@
@(Html.Telerik().Grid<CRF>().Name("CRFListSelfGrid")
    .ToolBar(config =>
    {
        config.Custom().Name("Add").Text("添加病例报告").Action<CRFController>(c => c.CRFAddSelf());
    })
    .DataKeys(keys => keys.Add(crf => crf.ID))
    .Columns(columns =>
    {
        columns.Bound(crf => crf.ID)
            .ClientTemplate("<input type='checkbox' name='checkRecords' value='<#= ID #>' />")
            .Title("")
            .Width(30)
            .HtmlAttributes(new { style = "text-align:center" });
        columns.Bound(crf => crf.HospitalCode).Title("医院编号");
        columns.Bound(crf => crf.CrfCode).Title("病例序号");
        columns.Bound(crf => crf.Patient.Name).Title("患者姓名");
        columns.Bound(crf => crf.ResearcherID).Hidden();
        columns.Bound(crf => crf.Researcher.RealName).Title("研究者");
        columns.BoundDate(crf => crf.StartTime).Title("开始时间");
        columns.Command(commands =>
        {
            commands.Custom("Detail").Text("详情").Ajax(true);
            if (LoginSession.IsAdministrator || LoginSession.IsOwner)
                commands.Delete();

        })
      .Title("操作");
    })
    .ClientEvents(events =>
    {
        events.OnCommand("OnCommand");
    })
    .DataBinding(bind =>
    {
        bind.Ajax().Select<CRFController>(c => c._CRFList(Model.ID))
            .Delete<CRFController>(c => c._CRFDelete(null));
    }
    ).Pageable(pager => pager.PageSize(10).Style(GridPagerStyles.NextPreviousAndNumeric))
    .Filterable(filtering => filtering
                .Filters(filters =>
                {
                    if (!string.IsNullOrWhiteSpace(ViewBag.HospitalCode as string))
                        filters.Add(o => o.HospitalCode).Contains(ViewBag.HospitalCode);
                    if (!string.IsNullOrWhiteSpace(ViewBag.CrfCode as string))
                        filters.Add(o => o.CrfCode).Contains(ViewBag.CrfCode);
                    if (!string.IsNullOrWhiteSpace(ViewBag.ResearcherName as string))
                        filters.Add(o => o.Researcher.RealName).Contains(ViewBag.ResearcherName);
                    if (!string.IsNullOrWhiteSpace(ViewBag.StartTime as string))
                        filters.Add(o => o.StartTime).Equals(Convert.ToDateTime(ViewBag.StartTime));

                }
      ))
    .Editable(edit => edit.Mode(GridEditMode.InLine))
    .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn).OrderBy(ord => ord.Add(o => o.StartTime)))
   )
  @*<input type="button" onclick="export()" value="导出" />*@
  <button onclick="export1()">导出</button>
  <div id="result"></div>
</text>
).Render();
}

<script type="text/javascript">
    function Detail(id) {
        var url = "@(Url.Action<CRFController>(c => c.CRFDetail(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }
    function export1() {
        var $checkRecords = $(':checked');

        if ($checkRecords.length < 1) {
            alert('Check a few grid rows first.');
            return;
        }
        var data = "";
        for (i = 0; i < $checkRecords.length; i++) {
            data += "checkRecords=" + $checkRecords.eq(i).val() + "&";
        }
        var url = "/CRF/Export?" + data;
        window.location = url;
    }

    function OnCommand(e) {
        switch (e.name) {
            case "Detail": Detail(e.dataItem.ID); break;
        }
    }
</script>
